<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="往来单位名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入往来单位名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" border :data="customerList">
      <el-table-column label="编号" align="center" prop="id" width="60"/>
      <el-table-column label="往来单位名称" align="center" prop="customerName" :show-overflow-tooltip="true"/>
      <el-table-column label="往来单位ID" align="center" prop="customerEntId" :show-overflow-tooltip="true"/>
      <el-table-column label="码上放心往来单位名称" align="center" prop="customerNameMsfx"/>
      <el-table-column label="操作" align="center" width="100px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['basic:customermap:edit']"
          >修改
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" @close="reset" append-to-body>
      <el-form :model="updateForm"  :rules="rules" ref="updateForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="往来单位名称" prop="customerName">
          <el-input v-model="updateForm.customerName" readonly/>
        </el-form-item>
        <el-form-item label="往来单位编号" prop="customerEntId">
          <el-input v-model="updateForm.customerEntId" readonly/>
        </el-form-item>
        <el-form-item label="码上放心往来单位名称" prop="customerNameMsfx">
          <el-input v-model="updateForm.customerNameMsfx" placeholder="请输入码上放心往来单位名称"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>

import {listErpCustomer,updateErpCustomer} from '@/api/msfx/mapping/customerMap'


export default {
  name: "customerMap",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 是否多选
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // ERP往来单位信息列表
      customerList: [],
      // 表单校验
      rules: {
        customerNameMsfx: [
          {require: true, message: "往来单位名称不能为空", trigger: "blur"},
        ]
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: ''
      },
      // 表单参数
      form: {},

      // 修改表单
      updateForm:{
        id: '',
        customerName: '',
        customerEntId: '',
        customerNameMsfx: ''
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询药品列表 */
    getList() {
      this.loading = true;
      listErpCustomer(this.queryParams).then(response => {
          this.customerList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.upload.customerList = [];
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.updateForm.id = row.id;
      this.updateForm.customerName = row.customerName;
      this.updateForm.customerEntId = row.customerEntId;
      this.updateForm.customerNameMsfx = row.customerNameMsfx;
      this.open = true;
      this.title = "修改往来单位映射";
    },

    // 文件提交处理
    submitForm() {
      this.$refs["updateForm"].validate(valid => {
          if (valid) {
            updateErpCustomer(this.updateForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        }
      )
    },
  }
};
</script>
